<style lang="less">
  @import './login.less';
</style>

<template>
  <div class="login" v-if="is_show" :style="{backgroundImage:'url(' + summary_v2 + ')'}">
    <div class="login-con">
      <hd-login :loginStyle="loginStyle" :fun="beforeLogin"></hd-login>
    </div>
  </div>
</template>

<script>
import HdLogin from './login/login'
import { mapActions } from 'vuex'
import Gmk from '@/view/summary_login/Gmk.vue'
import summary_v2 from '@/assets/summary/summary_v2.png'
export default {
  data () {
    return {
      summary_v2,
      loginStyle: {
        backgroundImage: 'url(' + summary_v2 + ')'
      },
      is_show: false,
      data: {
        userName: '',
        password: ''
      }
    }
  },
  components: {
    HdLogin
  },
  created () {
  },
  mounted (option) {
    console.log(this.$route.query.username, '12222')
    if (this.$route.query.username) {
      this.handleSubmit({ userName: this.$route.query.username, password: '000000' })
    } else {
      this.is_show = true
    }
  },
  methods: {
    ...mapActions([
      'handleLogin',
      'getUserInfo'
    ]),
    handleSubmit ({ userName, password }) {
      console.log('登录')
      this.handleLogin({ userName, password }).then(res => {
        if (res.errcode === 0) {
          if (res.data.errcode === 0) {
            // this.$Message.success('登录成功')
            this.getUserInfo().then(resx => {
              console.log(resx, this.$config.homeName, '用户信息')
              Gmk.userName = userName
              Gmk.password = password
              Gmk.currentUrl = window.location.href
              console.log(Gmk.currentUrl, '1a')
              if (Gmk.currentUrl.indexOf('localhost') !== -1) {
                Gmk.istest = true
                console.log(Gmk.istest, '2a')
              } else if (Gmk.currentUrl.indexOf('http://iview') !== -1) {
                console.log(Gmk.istest, '3a')
                Gmk.istest = true
              } else {
                console.log(Gmk.istest, '4a')
                Gmk.istest = false
              }
              this.$router.push({
                name: this.$config.homeName
              })
            })
          } else {
            this.$Message.error(res.data.errmsg)
          }
        } else {
          this.$Message.error(res.errmsg)
        }
      })
    },
    async beforeLogin () {
      let rest = await this.getUserInfo()
      console.log(rest)
      if (rest.errcode === 0) {
        return true
      } else {
        return true
      }
    }
  }
}
</script>

<style>

</style>
